import {
    CalendarActionType,
    ICtrlDataAction,
    ICtrlEvent,
    ICalendarAbility,
    ICalendarControllerParams,
    ICalendarModel,
    ICalendarStore,
    IParam,
    ICalendarController,
} from '@/core';
import { QXEvent } from 'qx-util';
import { PropType } from 'vue';
import {
    getCtrlClassNames,
    handleSortChange,
    useCtrlAction,
    useCtrlBasic,
    useCtrlControllerParams,
    useCtrlProps,
    handleCtrlAction,
    handleCtrlDestroy,
    handleCtrlInit,
} from '../use-ctrl';

/**
 * 日历输入参数
 *
 * @export
 * @return {*}
 */
export function useCalendarProps() {
    return {
        ...useCtrlProps(),
        openView: Function,
        newView: Function,
        actions: Object as PropType<ICtrlDataAction>,
        selectFirstDefault: Boolean,
    };
}

/**
 * 日历基础参数
 *
 * @export
 * @param {ICalendarModel} model
 * @param {IParam} props
 * @return {*}
 */
export function useCalendarBasic(model: ICalendarModel, props: IParam) {
    const getClassNames = (props: IParam) => {
        const names = getCtrlClassNames(model, props);
        return names;
    };
    return {
        ...useCtrlBasic(model, props),
        getClassNames,
        handleSortChange,
        handleCtrlAction,
        handleCtrlDestroy,
        handleCtrlInit,
    };
}

/**
 * 日历部件行为
 *
 * @export
 */
export function useCalendarAction(controller: ICalendarController<ICalendarStore,ICalendarAbility>) {
    // 加载事件
    const getEvents = (arg: IParam, callback: Function) => {
        controller.load({ arg, callback });
    }
    return {
        ...useCtrlAction(controller),
        getEvents,
    };
}

/**
 * 日历部件控制器
 *
 * @export
 */
export function useCalendarControllerParams<
    S extends ICalendarStore,
    M extends ICalendarModel
>(
    model: M,
    props: any,
    evt: QXEvent<ICtrlEvent<CalendarActionType, ICalendarAbility>>,
    otherParams: IParam = {},
): ICalendarControllerParams<CalendarActionType, ICalendarAbility> {
    return {
        ...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
        actions: props.actions,
        selectFirstDefault: props.selectFirstDefault,
        openView: props.openView,
        newView: props.newView,
    };
}
